<template>
  <div class="sidebar">
    <div class="sidebar-header">
      <h2>管理员后台</h2>
    </div>
    <nav>
      <ul>
        <li>
          <router-link to="/dashboard" aria-label="Go to dashboard">仪表盘</router-link>
        </li>
        <li>
          <router-link to="/orders" aria-label="Go to orders">查询订单</router-link>
        </li>
        <li>
          <router-link to="/orders/new" aria-label="Add new order">新增订单</router-link>
        </li>
        <li>
          <button @click="logout" aria-label="Logout">退出</button>
        </li>
      </ul>
    </nav>
  </div>
</template>

<script>
export default {
  methods: {
    logout() {
      if (confirm('您确定要退出吗？')) {
        localStorage.removeItem('authToken');
        this.$router.push('/login');
      }
    }
  }
};
</script>

<style scoped>
:root {
  --sidebar-width: 250px;
  --sidebar-bg-color: #2c3e50;
  --sidebar-text-color: white;
  --highlight-color: #3498db;
  --button-bg-color: #e74c3c;
  --sidebar-hover-color: #34495e;
}

.sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg-color);
  color: var(--sidebar-text-color);
  height: 100vh;
  padding: 20px;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  font-size: 1.5rem;
  margin-bottom: 20px;
}

nav ul {
  list-style: none;
  padding: 0;
}

nav ul li {
  margin-bottom: 15px;
}

nav ul li a {
  color: var(--sidebar-text-color);
  text-decoration: none;
  font-size: 1.2rem;
  padding: 10px;
  border-radius: 5px;
  display: block;
}

nav ul li a:hover {
  background-color: var(--sidebar-hover-color);
  color: var(--highlight-color);
}

nav ul li button {
  color: white;
  background-color: var(--button-bg-color);
  border: none;
  padding: 10px;
  cursor: pointer;
  width: 100%;
  border-radius: 5px;
}

nav ul li button:hover {
  background-color: #c0392b;
}

@media (max-width: 768px) {
  .sidebar {
    width: 200px;
    /* 缩小宽度，适应小屏幕 */
  }

  .sidebar-header h2 {
    font-size: 1.2rem;
  }

  nav ul li a {
    font-size: 1rem;
  }
}
</style>
